<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'pessoa.label', default: 'Pessoa')}" />
        <title><g:message code="default.edit.label" args="[entityName]" /></title>
    </head>
    <body>
      <div class="cabelistlateral"><img src="${resource(dir:'images',file:'seta_cabecalho_20x20.png')}" alt="" /> Lista de Usuário</div><br/>
        <div class="body">
            <g:hasErrors bean="${pessoaInstance}">
            <div class="errors">
                <g:renderErrors bean="${pessoaInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <g:hiddenField name="id" value="${pessoaInstance?.id}" />
                <g:hiddenField name="version" value="${pessoaInstance?.version}" />
                <div class="dialog dadospessoais">
                    <g:if test="${flash.message}">
                        <div class="message ui-corner-all">${flash.message}</div>
                    </g:if>
                    <table>
                        <tbody>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="status"><g:message code="pessoa.status.label" default="Status" /></label>
                                </td>
                                <%
                                String st = "";
                                style     = "";
                                if(pessoaInstance.status == "1"){
                                  st = "Ativo";
                                  style     = " style='color:#006600; font-weight:bold; font-size:14px;'";
                                }else{
                                  st = "Inativo";
                                  style     = " style='color:#ff0000; font-weight:bold; font-size:14px;'";
                                }
                                %>
                                <td<%=style%>>
                                    <%=st%>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="nome"><g:message code="pessoa.nome.label" default="Nome Completo" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'nome', 'errors')}">
                                    <g:textField name="nome" maxlength="100" size="50" value="${pessoaInstance?.nome}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="username"><g:message code="pessoa.username.label" default="Username" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'username', 'errors')}">
                                    <g:textField name="username" maxlength="60" value="${pessoaInstance?.username}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="password"><g:message code="pessoa.password.label" default="Password" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'password', 'errors')}">
                                    <g:passwordField name="password" value="${pessoaInstance?.password}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="banco"><g:message code="pessoa.banco.label" default="Banco" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'banco', 'errors')}">
                                    <g:textField name="banco" value="${pessoaInstance?.banco}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="ag"><g:message code="pessoa.ag.label" default="Agência" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'ag', 'errors')}">
                                    <g:textField name="ag" value="${pessoaInstance?.ag}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="cc"><g:message code="pessoa.cc.label" default="Conta Correte" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pessoaInstance, field: 'cc', 'errors')}">
                                    <g:textField name="cc" value="${pessoaInstance?.cc}" />
                                </td>
                            </tr>

                            <tr>
                              <td></td>
                              <td class="btsalvarcadastro">
                                  <g:actionSubmit class="ui-corner-all" action="update" value="ATUALIZAR" />
                                  <g:actionSubmit class="ui-corner-all" action="delete" value="EXCLUIR" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
                                  <%
                                  if(pessoaInstance.status == "0"){
                                      %>
                                      <input type="button" class="ui-corner-all" value="ATIVAR" onclick="location.href='${createLink(controller:'pessoa', action:'ativarCadastro', id:pessoaInstance?.id, params:[status:1])}';" />
                                      <%
                                  }else{
                                      %>
                                      <input type="button" class="ui-corner-all" value="DESATIVAR" onclick="location.href='${createLink(controller:'pessoa', action:'desativarCadastro', id:pessoaInstance?.id, params:[status:0])}';" />
                                      <%
                                  }
                                  %>
                                  <input type="button" class="ui-corner-all" value="VOLTAR" onclick="location.href='${createLink(controller:'pessoa', action:'list')}';" />
                              </td>
                            </tr>

                        </tbody>
                    </table>
                </div>

            </g:form>

              <div class="dadoslateral ui-corner-all">
                    <div class="contatos">
                    <h1 class="cabelistlateral">Regras</h1>
                    <g:hasErrors bean="${roleInstance}">
                    <div class="errors">
                        <g:renderErrors bean="${roleInstance}" as="list" />
                    </div>
                    </g:hasErrors>
                    <sec:ifAnyGranted roles="ROLE_ADMIN">
                    <form method="post" action="/EstagioWeb/pessoa/savePessoaRole">
                        <input type="hidden" name="pessoa.id" value="${pessoaInstance.id}"/>
                        <div class="dialog">
                            <table>
                                <tbody>
                                    <tr class="prop cadastrolateral">
                                        <td valign="top" class="name" class="value ${hasErrors(bean: roleInstance, field: 'authority', 'errors')}">
                                            <label for="authority"><g:message code="role.authority.label" default="Selecione a Regra" /></label>
                                            <br/>
                                            <g:select name="role.id" from="${Role.list()}" optionKey="id" value="" optionValue="authority" class="camposelect" />
                                        </td>
                                        <td class="btsalvarlateral">
                                          <g:submitButton name="create" class="save ui-corner-all" value="SALVAR" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </form>
                    </sec:ifAnyGranted>  
                    </div>
                    <%
                    if(roleInstanceList){
                        %>
                        <div class="list">
                            <table>
                                <thead>
                                    <tr>
                                        <g:sortableColumn property="authority" title="${message(code: 'role.authority.label', default: 'Authority')}" />
                                        <sec:ifAnyGranted roles="ROLE_ADMIN">
                                          <td class="acao">Ações</td>
                                        </sec:ifAnyGranted>  
                                    </tr>
                                </thead>
                                <tbody>
                                <g:each in="${roleInstanceList}" status="i" var="roleInstance">
                                    <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                                        <td>${fieldValue(bean: roleInstance, field: "authority")}</td>
                                        <sec:ifAnyGranted roles="ROLE_ADMIN">
                                        <td class="ico">
                                            <a href="${createLink(uri: '/pessoa/deleteRole?idPessoa=' + pessoaInstance.id + '&idRole=' + roleInstance.id)}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Confirma aexclusão do registro?')}');">
                                                <img src="${resource(dir:'images',file:'ico_delete.png')}" alt="Excluir Item" title="Excluir Item" class="formacao" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}"  />
                                            </a>
                                        </td>
                                        </sec:ifAnyGranted>
                                    </tr>
                                </g:each>
                                </tbody>
                            </table>
                        </div>
                        <div class="paginateButtons">
                            <g:paginate total="${roleInstanceTotal}" />
                        </div>
                        <%
                    }
                    %>
              </div>

              <%
              if(UnidadeConcedente.findById(pessoaInstance.id) || InstituicaoEnsino.findById(pessoaInstance.id)){
                  %>
                  <div class="dadoslateral ui-corner-all">
                  <h1 class="cabelistlateral">Convênios</h1>
                  <g:hasErrors bean="${convenioInstance}">
                  <div class="errors">
                      <g:renderErrors bean="${convenioInstance}" as="list" />
                  </div>
                  </g:hasErrors>
                  <%
                  if(convenioInstance?.id){
                      %>
                      <form method="post" action="${createLink(controller:'convenio', action:'update', id:convenioInstance.id)}">
                      <%
                  }else{
                      %>
                      <form method="post" action="${createLink(controller:'convenio', action:'save')}">
                      <%
                  }
                  %>
                      <g:hiddenField name="colaborador.id" value="${pessoaInstance.id}" />
                      <g:hiddenField name="tipo" value="pessoa" />
                      <div class="dialog">
                          <table>
                              <tbody>

                                  <tr class="prop cadastrolateral">
                                      <td valign="top" class="name" class="value ${hasErrors(bean: convenioInstance, field: 'dtInicio', 'errors')}">
                                          <label for="dtInicio"><g:message code="convenio.dtInicio.label" default="Data Inicio" /></label>
                                          <br/>
                                          <g:datePicker name="dtInicio" precision="day" value="${convenioInstance?.dtInicio}"  />
                                      </td>
                                      <td valign="top" class="name" class="value ${hasErrors(bean: convenioInstance, field: 'dtTermino', 'errors')}">
                                          <label for="dtTermino"><g:message code="convenio.dtTermino.label" default="Data Término" /></label>
                                          <br/>
                                          <g:datePicker name="dtTermino" precision="day" value="${convenioInstance?.dtTermino}" default="none" noSelection="['': '']" />
                                      </td>
                                  </tr>

                                  <tr class="prop cadastrolateral">
                                      <td valign="top" colspan="2" class="name" class="value ${hasErrors(bean: convenioInstance, field: 'motivoRescisao', 'errors')}">
                                          <label for="motivoRescisao"><g:message code="convenio.motivoRescisao.label" default="Motivo Rescisao" /></label>
                                          <br/>
                                          <g:textArea name="motivoRescisao" cols="45" rows="2" value="${convenioInstance?.motivoRescisao}" />
                                      </td>
                                  </tr>

                                  <tr class="prop cadastrolateral">
                                      <td valign="top" class="name" class="value ${hasErrors(bean: convenioInstance, field: 'dtRescisao', 'errors')}">
                                          <label for="dtRescisao"><g:message code="convenio.dtRescisao.label" default="Data Rescisão" /></label>
                                          <br/>
                                          <g:datePicker name="dtRescisao" precision="day" value="${convenioInstance?.dtRescisao}" default="none" noSelection="['': '']" />
                                      </td>
                                      <td class="btsalvarlateral">
                                        <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
                                      </td>
                                  </tr>
                              </tbody>
                          </table>
                      </div>
                  </form>
                  <%
                  if(convenioInstanceList){
                      %>
                      <div class="list">
                          <table>
                              <thead>
                                  <tr>
                                      <g:sortableColumn property="dtInicio" title="${message(code: 'convenio.dtInicio.label', default: 'Data Início')}" />
                                      <g:sortableColumn property="dtTermino" title="${message(code: 'convenio.dtTermino.label', default: 'Data Término')}" />
                                      <td>Status</td>
                                      <td class="acao">Ações</td>
                                  </tr>
                              </thead>
                              <tbody>
                              <g:each in="${convenioInstanceList}" status="i" var="convenioInstance">
                                  <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                                      <%
                                          String st = "";
                                          style     = "";
                                          if(!convenioInstance?.dtRescisao){
                                              if(convenioInstance?.dtTermino.after(new Date())){
                                                st = "Ativo";
                                                style     = " style='color:#006600; font-weight:bold;'";
                                              }else{
                                                st = "Inativo";
                                                style     = " style='color:#ff0000; font-weight:bold;'";
                                              }
                                          }else{
                                               st = "Recindido";
                                               style     = " style='color:#f78b00; font-weight:bold;'";
                                          }
                                          %>
                                      <td><g:formatDate date="${convenioInstance.dtInicio}" format="dd-MM-yyyy"/></td>
                                      <td><g:formatDate date="${convenioInstance.dtTermino}" format="dd-MM-yyyy"/></td>
                                      <td<%=style%>><%=st%></td>
                                      <td class="ico">
                                        <a href="${createLink(controller:'convenio', action:'edit', id:convenioInstance.id, params:[tipo:"pessoa", colaborador:pessoaInstance.id])}">
                                          <img src="${resource(dir:'images',file:'ico_edit.png')}" alt="Editar Item" title="Editar Item" />
                                        </a>
                                      </td>
                                  </tr>
                              </g:each>
                              </tbody>
                          </table>
                      </div>
                      <%
                  }
                  %>
                  </div>
                  <%
              }
              %>
        </div>

    </body>
</html>
